package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.constant.type.InvoiceTypeEnum;
import com.zzl.bonds.ticket.entity.TicketDataEntity;
import com.zzl.bonds.ticket.service.TicketDataService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 开立或转让上传的资料
 *
 * @author sunpp
 * @date 2022-02-16 11:14:06
 */
@ApidocController("4开立或转让上传的资料")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("bondsticket/tickedata")
@Slf4j
public class TicketDataController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketDataService ticketDataService;


    @GetMapping("/getInvoiceType")
    @ApidocOperation(description = "1发票类型下拉框", operationId = "aa/ticket/ticketopen/getInvoiceType")
    @ApidocReturnR
    public Result getInvoiceType() {
        return Result.ok().put("list", InvoiceTypeEnum.list());
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询开立或转让上传的资料数据", operationId = "4011")
    @ApidocReturnPage(genericTypeClass = TicketDataEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = ticketDataService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取开立或转让上传的资料数据", operationId = "4012")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "tickedata", valueClass = TicketDataEntity.class)
    })
    public Result info(@ApidocParam(name = "开立或转让上传的资料id", required = true) @PathVariable("id") String id) {
        TicketDataEntity tickedata = ticketDataService.getById(id);
        return Result.ok().put("tickedata", tickedata);
    }


    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除开立或转让上传的资料", operationId = "4015")
    @ApidocReturnR
    public Result delete(@ApidocParam(name = "删除的开立或转让上传的资料对象id集合", required = true) @RequestBody String[] ids) {
        ticketDataService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
